package com.itheima.demo05;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/13 18:32
 */
public class Ticket implements Runnable {
    private int ticket = 100;

    @Override
    public void run() {

        while (true) {
            synchronized (this) {
                if (ticket == 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "正在售票,还剩下" + ticket + "张票");
                }
            }
        }
    }
}
